package com.raycloud.util;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by donar on 17/4/28.
 */
public class GitLabUtils {
    static private String PRIVATE_TOKEN="FmxEM8aKMi6t9nowo-GT";
    public static List<Object> getProjectList(){
        Map<String,String> headerMap = new HashMap<String,String>();
        headerMap.put("PRIVATE-TOKEN",PRIVATE_TOKEN);
        String content  = HttpUtil.getContent("http://git.superboss.cc/api/v3/projects?order_by=last_activity_at&sort=desc&page=1",headerMap);
        JSONArray array = JSON.parseArray(content);
        String content2  = HttpUtil.getContent("http://git.superboss.cc/api/v3/projects?order_by=last_activity_at&sort=desc&page=2",headerMap);
        JSONArray array2 = JSON.parseArray(content2);
        array.addAll(array2);
        return array.toJavaList(Object.class);
    }
    public static List<Object> getBranchList(String id){
        Map<String,String> headerMap = new HashMap<String,String>();
        headerMap.put("PRIVATE-TOKEN",PRIVATE_TOKEN);
        String content  = HttpUtil.getContent("http://git.superboss.cc/api/v3/projects/"+id+"/repository/branches",headerMap);
        JSONArray array = JSON.parseArray(content);
        return array.toJavaList(Object.class);
    }

    public static void main(String[] args) {
        System.out.println(JSON.toJSONString(getBranchList("702")));
    }
}
